
$(function (){
	initGrid();
	$("#grid_btn_add").click(function (){
		RM.btn.add($(this),$("#button-table"));
	});
	
	//删除
	$("#del_grid-table").click(function (){
		RM.jqgrid.dels($("#button-table"),"dels.do");
	});
	
	$("#grid_btn_edit").click(function (){
		var grid = $("#button-table");
		var ids = RM.jqgrid.ids(grid);
		if(ids.length == 0){
			RM.msg("请选择一行数据进行编辑");
		}else{
			RM.btn.edit($(this),grid,ids[0]);
		}
	});
});

function initGrid(){
	$("#button-table").jqGrid({
		 url:'/system/button/list.do',
		 mtype: 'POST',
		 datatype : "json",
		 autowidth:true,
		 multiselect: true,
		 multiboxonly:true,
		 colNames:['ID', '名称','权限字符串','所属菜单','菜单ID'],
		 colModel:[
			{name:'id',index:'id', width:60, editable:false, edittype:'text',hidden:true},
			{name:'name',index:'name', width:90, editable:true, edittype:'text'},
			{name:'permission',index:'permission', width:90, editable:true, edittype:'text'},
			{name:'menu.name',index:'menu.name', width:90, editable:true, edittype:'text'},
			{name:'menu.id',index:'menu.id', width:90, editable:true, edittype:'text',hidden:true}
			/*{name:'操作',index:'',width:90,algin:'center',
				formatter: function (cellvalue, options, rowObject) {
                    return "<img width='15' onclick='imgClick(\"" + options.rowId +"\",0)' src='/static/assets/images/gallery/image-1.jpg'/>";
                }
			}*/
		 ],
		loadComplete : function() {
			updatePagerIcons(this);
		},
		rowNum:15,
		pager: "#button-pager",
		viewrecords : true
	});
	
	$("#button-table").jqGrid('navGrid',"#button-pager",
	{
		edit: false,
		editicon : 'icon-pencil blue',
		add: false,
		addicon : 'icon-plus-sign purple',
		del: false,
		delicon : 'icon-trash red',
		search: false,
		searchicon : 'icon-search orange',
		refresh: false,
		refreshicon : 'icon-refresh green',
		view: false,
		viewicon : 'icon-zoom-in grey',
	},{
		
	},{
		
	},
	{
		
	},
	{
		
	},
	{
		/*recreateForm: true,
		beforeShowForm: function(e){
			var form = $(e[0]);
			form.closest('.ui-jqdialog').find('.ui-jqdialog-title').wrap('<div class="widget-header" />');
		}*/
	});
}